package com.example.homework;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.homework.utils.GoodInfo;

import java.util.List;

public class goodsListAdapter extends RecyclerView.Adapter<MyViewHolder> {

   // private List<Good> mList;
    private List<GoodInfo> mList;

    private Activity mActivity;
    private MyViewHolder viewHolder;
    private GoodInfo goodInfo;

    public goodsListAdapter(Activity mActivity, List<GoodInfo> mList) {
        this.mActivity = mActivity;
        this.mList = mList;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        viewHolder = new MyViewHolder(View.inflate(mActivity, R.layout.good_list_item, null));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        goodInfo = mList.get(position);
        holder.title.setText(goodInfo.getName());
        holder.price.setText(""+goodInfo.getPrice());
        holder.count.setText(goodInfo.getVolume()+"人付款");
        holder.address.setText(goodInfo.getProductLocation());
        holder.shopName.setText(goodInfo.getShopName());
        holder.imageView.setImageResource(goodInfo.getImage());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }
}
